﻿Imports Microsoft.VisualBasic.PowerPacks
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class PatternLineShape
    Inherits LineShape
    Private M_PStart As Point
    Private M_PStop As Point
    Private m_BodyColor As Color
    Private m_IdentColor As Color = Color.White
    Private m_BodyWidth As Integer
    Private m_IdentWidth As Integer = 2
    Private m_LineStyle As LineStyleConstants = LineStyleConstants.Line

    Public Enum LineStyleConstants
        Solid = 0
        Line = 1
        Circle = 2
        Square = 3
        Hatch = 4
    End Enum
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        DrawPatternLine(e)
    End Sub
    Private Sub DrawPatternLine(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim G As Graphics = e.Graphics
        G.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        G.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        Dim X1 As Integer = StartPoint.X
        Dim X2 As Integer = EndPoint.X
        Dim Y1 As Integer = StartPoint.Y
        Dim Y2 As Integer = EndPoint.Y
        m_BodyColor = BorderColor
        m_BodyWidth = BorderWidth

        If m_LineStyle = LineStyleConstants.Solid Then
            Dim Pen1 As New Pen(m_BodyColor, m_BodyWidth)
            G.DrawLine(Pen1, X1, Y1, X2, Y2)
            Dim Pen2 As New Pen(m_IdentColor, m_IdentWidth)
        End If
        If m_LineStyle = LineStyleConstants.Line Then
            Dim Pen1 As New Pen(m_BodyColor, m_BodyWidth)
            G.DrawLine(Pen1, X1, Y1, X2, Y2)
            Dim dashValues As Single() = {2, 2}
            Dim Pen2 As New Pen(m_IdentColor, m_IdentWidth)
            Pen2.DashPattern = dashValues
            G.DrawLine(Pen2, X1, Y1, X2, Y2)
        End If

        If m_LineStyle = LineStyleConstants.Circle Then
            Dim IdentBmp As New Bitmap(m_BodyWidth, m_BodyWidth, Imaging.PixelFormat.Format24bppRgb)
            Dim Ig As Graphics = Graphics.FromImage(IdentBmp)
            Ig.Clear(m_BodyColor)
            Dim Cx As Integer = (m_BodyWidth / 2) - m_IdentWidth / 2
            Dim Cy As Integer = Cx
            Dim Cw As Integer = m_IdentWidth / 2
            Dim Ch As Integer = Cw
            Ig.FillEllipse(New SolidBrush(m_IdentColor), Cx, Cy, Cw, Ch)
            Dim myBrush As New TextureBrush(IdentBmp)
            Dim Pen1 As New Pen(myBrush, m_BodyWidth)
            G.DrawLine(Pen1, X1, Y1, X2, Y2)
        End If

        If m_LineStyle = LineStyleConstants.Square Then
            Dim IdentBmp As New Bitmap(m_BodyWidth, m_BodyWidth, Imaging.PixelFormat.Format24bppRgb)
            Dim Ig As Graphics = Graphics.FromImage(IdentBmp)
            Ig.Clear(m_BodyColor)
            Dim Cx As Integer = (m_BodyWidth / 2) - m_IdentWidth / 2
            Dim Cy As Integer = Cx
            Dim Cw As Integer = m_IdentWidth / 2
            Dim Ch As Integer = Cw
            Ig.FillRectangle(New SolidBrush(m_IdentColor), Cx, Cy, Cw, Ch)
            Dim myBrush As New TextureBrush(IdentBmp)
            Dim Pen1 As New Pen(myBrush, m_BodyWidth)
            G.DrawLine(Pen1, X1, Y1, X2, Y2)
        End If

        If m_LineStyle = LineStyleConstants.Hatch Then
            Dim myBrush As New System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Plaid, m_BodyColor, m_IdentColor)
            Dim Pen1 As New Pen(myBrush, m_BodyWidth)
            G.DrawLine(Pen1, X1, Y1, X2, Y2)
        End If
    End Sub
    Public Property IdentColor() As Color
        Get
            Return m_IdentColor
        End Get
        Set(ByVal value As Color)
            m_IdentColor = value
            Me.Refresh()
        End Set
    End Property
    Public Property IdentWidth() As Integer
        Get
            Return m_IdentWidth
        End Get
        Set(ByVal value As Integer)
            m_IdentWidth = value
            Me.Refresh()
        End Set
    End Property
    Public Property LineStyle() As LineStyleConstants
        Get
            Return m_LineStyle
        End Get
        Set(ByVal value As LineStyleConstants)
            m_LineStyle = value
            Me.Refresh()
        End Set
    End Property

End Class